﻿/*****************************************************************//**
 * @file    FITKGraphObjectGeoModelBase.h
 * @brief   Geometry graph object base for VTK graph widget.
 * 
 * @sa
 * FITKPartDataSetManager FITKGraphObjectModelHighlighting
 *
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-11-15
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTGEOMODELBASE_H__
#define __FITKGRAPHOBJECTGEOMODELBASE_H__

#include "FITKGraphObjectModelBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

#include <QVector>

// Forward declaration
class vtkDataSet;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkDataSet;
class vtkDoubleArray;

class FITKGraphActor;

namespace Interface
{
    class FITKAbsGeoCommand;
    class FITKGeometryMeshVS;
    class FITKVirtualTopoManager;
}

namespace AbaqusData
{
    class FITKAbaqusPart;
}

namespace Exchange
{
    class FITKGraphObjectModelHighlighting;
}

/**
 * @brief   The geometry shape type.
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-12-02
 */
enum GeomShapeType
{
    GST_None = -1,
    GST_Vertex = 0,
    GST_Edge,
    GST_Face,
    // GST_Solid
};

namespace Exchange
{
    /**
     * @brief   Geometry graph object base for VTK graph widget.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-11-15
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectGeoModelBase : public FITKGraphObjectModelBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectGeoModelBase, FITKGraphObjectModelBase);
        FITKCLASS(Exchange, FITKGraphObjectGeoModelBase);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   dataObj: The data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        FITKGraphObjectGeoModelBase(AbaqusData::FITKDataCase* caseData, Core::FITKAbstractDataObject* dataObj);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        virtual ~FITKGraphObjectGeoModelBase() = default;

        /**
         * @brief   Update all graph actors.[virtual][override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        virtual void update(bool forceUpdate = false) override;

        /**
         * @brief   Show or hide the mesh point.[virtual][override]
         * @param   visible: The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void setPointVisible(bool visible) override;

        /**
         * @brief   Enable or disable transparent.[virtual]
         * @param   isOn: Enable or disable
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        virtual void setTransparent(bool isOn);

        /**
         * @brief   Highlight model.[virtual][override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-27
         */
        virtual void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight model.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-27
         */
        virtual void disHighlight() override;

        /**
         * @brief   Pre-highlight the graph actors.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-29
         */
        virtual void preHighlight() override;

        /**
         * @brief   Set if the graph object can be picked.[virtual][override]
         * @param   isPickable: Pickable
         * @param   dim: The dimision of the pickable object( -1 means the whole graph object )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-29
         */
        virtual void setPickable(bool isPickable, int dim = -1) override;

        /**
         * @brief   Unused.[virtualoverride
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void colorByDoubleFaces(bool forceUpdate = false) override
        {
            Q_UNUSED(forceUpdate);
        }

        /**
         * @brief   Get the command id by the given shape type and VTK cell id.[virtual]
         * @param   vtkCellId: The VTK cell id in shape data
         * @param   shapeType: The shape type of the given ID[default]
         * @return  The shape id
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-03
         */
        virtual int getCmdIdByVTKCellId(int vtkCellId, GeomShapeType shapeType = GeomShapeType::GST_None);

        /**
         * @brief   Get the shape id by the given shape type and VTK cell id.[virtual]
         * @param   vtkCellId: The VTK cell id in shape data
         * @param   shapeType: The shape type of the given ID[default]
         * @return  The shape id
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual int getShapeIdByVTKCellId(int vtkCellId, GeomShapeType shapeType = GeomShapeType::GST_None);

        /**
         * @brief   Get the VTK cell indice by the given shape type and shape id in shape data.[virtual]
         * @param   shapeId: The shape id in shape data
         * @param   topAbsShapeType: The shape type of the given ID( the same as TopAbs_ShapeEnum )
         * @return  The cell indice[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual const QVector<int> getVTKCellIdsByShapeId(int shapeId, GeomShapeType shapeType = GeomShapeType::GST_None);

        /**
         * @brief   Get the vtkDataSet by the given shape type.[virtual]
         * @param   shapeType: The geometry shape type
         * @return  The vtkDataSet
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-03
         */
        virtual vtkDataSet* getMeshByGeomType(GeomShapeType shapeType);

    protected:
        /**
         * @brief   Initialize.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        virtual void init();

        /**
         * @brief   Get the part data object from the data object of the graph.[pure virtual]
         * @return  The part data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-11
         */
        virtual AbaqusData::FITKAbaqusPart* getPartData() = 0;

        /**
         * @brief   Abandonded.[virtual]
         * @param   forceUpdate: Force update the geometry dataset
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        virtual bool generateDataSet(bool forceUpdate = false);

        /**
         * @brief   Generate the shape with the vtkDataSet.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        virtual void generateGraph();

    protected:
        /**
         * @brief   The model actor for vertice.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        FITKGraphActor* m_fActorVertex{ nullptr };

        /**
         * @brief   The model actor for edges.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        FITKGraphActor* m_fActorEdge{ nullptr };

        /**
         * @brief   The model actor for faces.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-15
         */
        FITKGraphActor* m_fActorFace{ nullptr };

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTGEOMODELBASE_H__
